package com.ac.app.web.action.pick;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.ac.app.dm.*;
import com.ac.app.service.PickManager;
import com.caac.core.util.ListMapClass;
import com.caac.core.web.action.BaseAction;
import com.caac.core.web.form.BaseForm;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright AgileCentury 2008</p>
 * <p>Company: AgileCentury </p>
 * @author <a href="mailto:ac@agilecentury.com">Agile</a>
 * @version 1.0
 */

public class HandPickAction extends BaseAction {
    private ListMapClass entrys = new ListMapClass();

    protected ActionForward doExecute(ActionMapping mapping,
                                      BaseForm form,
                                      HttpServletRequest request,
                                      HttpServletResponse response)
            throws Exception {
        String[] ids = request.getParameterValues("id");
        String[] subs = request.getParameterValues("subs");
        PickManager pm = (PickManager) this.getBean("pickManager");
        PickBase pbDm = pm.getPickBase();
        List peList = pm.getPickEntrys();
        for (int i = 0; i < peList.size(); i++) {
            PickEntry pe = (PickEntry) peList.get(i);
            entrys.addChild(pe.getId(), pe);
        }

        List puList = pm.getPickUrls(ids);
        for (int i = 0; i < puList.size(); i++) {
            PickUrl puDm = (PickUrl) puList.get(i);
            PickEntry peDm = (PickEntry) entrys.getChild(puDm.getEntryId());
            pm.savePickRecord(peDm, puDm, subs, pbDm.getShotPath());
        }

        return forward(mapping);
    }
}
